﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Mtbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;
namespace HKEA.CMS.Core.BLL.Mtbl
{
    public class mtblBrandBLL
    {
        private ImtblBrand IDAL;
        public mtblBrandBLL()
        {
            IDAL = DataAccess.CreateImtblBrand();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static mtblBrandBLL GetInstance()
        {
            return new mtblBrandBLL();
        }
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(mtblBrand ent)
        {
            int ret = 0;
            if (InsertENTReturnENT(ent) != null)
            {
                ret = 1;
            }
            return ret;
        }
        public mtblBrand InsertENTReturnENT(mtblBrand ent)
        {
            if (ent != null)
            {
                try
                {
                    ent = IDAL.InsertENT(ent);
                }
                catch (Exception er)
                {

                    throw;
                }
            }
            return ent;
        }


        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(mtblBrand ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        public List<M_BrandListDetail> GetListByCustUID(List<int> ids, int CustomerUID)
        {
            var list = new List<M_BrandListDetail>();
            if (CustomerUID > 0)
            {
                try { list = IDAL.GetListByCustUID(ids, CustomerUID); }
                catch (Exception er) { throw; }
            }
            return list;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(mtblBrand ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<mtblBrand> GetListByENT(mtblBrand ent,PageParam param, string strPropertyName,string strOrderBy)
        {
            List<mtblBrand> list=new List<mtblBrand>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public List<BrandListDetail> GetListDetailByENT(mtblBrand ent)
        {
            List<BrandListDetail> list = new List<BrandListDetail>();
            if (ent != null)
            {
                try { list = IDAL.GetListDetailByENT(ent); }
                catch (Exception er)
                { throw; }
            }
            return list;
        }

        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<mtblBrand> GetListByENT(mtblBrand ent)
        {
            List<mtblBrand> list = new List<mtblBrand>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public mtblBrand GetEntity(mtblBrand ent)
        {
            var list = GetListByENT(ent);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }
        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(mtblBrand ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(mtblBrand ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
